"""
-------------------------------
- File_Name: docs.py
- Date: 2025/2/8
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: Swagger-ui 静态文件
-------------------------------
"""

from fastapi import APIRouter, FastAPI
from config import get_settings
from fastapi.openapi.docs import get_swagger_ui_html,get_redoc_html,get_swagger_ui_oauth2_redirect_html

settings = get_settings()

# 接口前缀
root_path = settings["root_path"]

router = APIRouter(dependencies=None)
tags = ["Swagger-ui 静态文件"]
description = "无网络的情况下，使用本地Swagger-ui"


@router.get("/docs", include_in_schema=False,summary="本地静态SwaggerUI")
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url="/openapi.json",
        title=settings["title"] + " - Swagger UI",
        oauth2_redirect_url="/docs/oauth2-redirect",
        swagger_js_url=f"{root_path}/static/SwaggerUI/swagger-ui-bundle.js",
        swagger_css_url=f"{root_path}/static/SwaggerUI/swagger-ui.css",
        swagger_favicon_url=f"{root_path}/static/SwaggerUI/favicon.ico",
    )

@router.get("/docs/oauth2-redirect",include_in_schema=False, summary="本地静态oauth2-redirect")
async def swagger_ui_redirect():
    return get_swagger_ui_oauth2_redirect_html()

@router.get("/redoc", include_in_schema=False, summary="本地静态Redoc文档")
async def redoc_html():
    return get_redoc_html(
        openapi_url="/openapi.json",
        title=settings["title"] + " - ReDoc",
        redoc_js_url=f"{root_path}/static/SwaggerUI/redoc.standalone.js",
        redoc_favicon_url=f"{root_path}/static/SwaggerUI/favicon.ico",
    )

def register_router_doc(app: FastAPI):
    app.include_router(router, tags=tags)